package cn.itcast.controller;

import cn.itcast.entity.MessageConstant;
import cn.itcast.entity.PageResult;
import cn.itcast.entity.QueryPageBean;
import cn.itcast.entity.Result;
import cn.itcast.pojo.CheckGroup;
import cn.itcast.service.CheckGroupService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/checkgroup")
public class CheckGroupController {

    @Reference
    CheckGroupService service;

    //获取对象，获取数组用于添加操作
    @RequestMapping("/add.do")
    public Result add(@RequestBody CheckGroup group, Integer[] checkitemIds) {

        try {

            service.add(group,checkitemIds);

        }catch(Exception e){
            e.printStackTrace();
            return new  Result(false, MessageConstant.ADD_CHECKGROUP_FAIL);
        }


        return new Result(true, MessageConstant.ADD_CHECKGROUP_SUCCESS);

    }


    @RequestMapping("/findPage.do")
    public PageResult findPage(@RequestBody QueryPageBean bean) {

       // PageResult result = service.findPage(bean);

        return service.findPage(bean);

    }


    @RequestMapping("/findById.do")//400
    public CheckGroup findById(String id) {

        return service.findById(id);
    }


    @RequestMapping("/findAll.do")
    public List<CheckGroup> findAll() {

        return service.findAll();
    }

}
